package com.igeekhome.egobuycontentservice.controller;

import com.igeekhome.egobuy.content.pojo.TbContent;
import com.igeekhome.egobuy.util.ResponseEntity;
import com.igeekhome.egobuycontentservice.service.TbContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author : FMH
 * @Date : 2020/3/3 17:38
 * @Description :
 * @Modify By : 86159
 * @Version :
 */
@RestController
@RequestMapping("/content")
public class ContentController {

    @Autowired
    private TbContentService tbContentService;

    @RequestMapping("/list")
    public ResponseEntity list(){
        List<TbContent> tbContents = tbContentService.queryAllByLimit(0, 0);
        return ResponseEntity.success(tbContents);
    }

    @RequestMapping("/list/{categoryId}")
    public ResponseEntity listByCategoryId(@PathVariable Long categoryId){
        List<TbContent> tbContents = tbContentService.queryAllByCategoryId(categoryId);
        return ResponseEntity.success(tbContents);
    }

    @RequestMapping("/add")
    public ResponseEntity add(TbContent tbContent) {
        tbContentService.insert(tbContent);
        return ResponseEntity.success();
    }

    @RequestMapping("/update")
    public ResponseEntity update(TbContent tbContent) {
        tbContentService.update(tbContent);
        return ResponseEntity.success();
    }
    @RequestMapping("/delete/{id}")
    public ResponseEntity delete(@PathVariable Long id) {
        tbContentService.deleteById(id);
        return ResponseEntity.success();
    }

}
